/*
 * Image.cpp
 *
 *  Created on: 14/11/2011
 *      Author: joagf
 */

#include "Image.h"

Image::Image(const string &filename,const Point2d &pos) :
  pos_(pos)
{

  SDL_Surface* loadedImage = NULL;
  SDL_Surface* optimizedImage = NULL;

  /*Carrega a imagem*/
  loadedImage = IMG_Load( filename.c_str() );

  if( loadedImage != NULL )
  {
          optimizedImage = SDL_DisplayFormat( loadedImage );
          SDL_FreeSurface( loadedImage );
          if( optimizedImage != NULL )
          {
                  SDL_SetColorKey( optimizedImage, SDL_SRCCOLORKEY, SDL_MapRGB( optimizedImage->format, 0, 0xFF, 0xFF ) );
          }
  }
  img_ = optimizedImage;

}

Image::~Image()
{
	/*if(img_)
	{
		SDL_FreeSurface(img_);
	}*/
}



SDL_Surface* Image::getImg()
{
  return img_;
}

const Point2d& Image::getPos()
{
  return pos_;
}

void Image::setPos(const Point2d &pos)
{
	pos_ = pos;
}

void Image::setColorKey(const ColorsRGB &cor)
{
	SDL_SetColorKey( img_, SDL_SRCCOLORKEY, SDL_MapRGB( img_->format, cor.r_, cor.g_,cor.b_) );
}
